package com.zyf.wjy.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.zyf.wjy.entity.PlantingPlan;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 种植计划DAO
 */
@Repository
public class PlantingPlanDao extends BaseDao<PlantingPlan> {
    
    @Override
    protected String getFileName() {
        return "planting_plans.json";
    }
    
    @Override
    protected TypeReference<List<PlantingPlan>> getTypeReference() {
        return new TypeReference<List<PlantingPlan>>() {};
    }
    
    @Override
    protected Long getId(PlantingPlan entity) {
        return entity.getId();
    }
    
    @Override
    protected void setId(PlantingPlan entity, Long id) {
        entity.setId(id);
    }
    
    /**
     * 根据状态查询
     */
    public List<PlantingPlan> findByStatus(String status) {
        return findAll().stream()
            .filter(plan -> status.equals(plan.getStatus()))
            .toList();
    }
    
    /**
     * 根据地块ID查询
     */
    public List<PlantingPlan> findByFieldId(Long fieldId) {
        return findAll().stream()
            .filter(plan -> fieldId.equals(plan.getFieldId()))
            .toList();
    }
}

